﻿<%@ Page Language="C#" MasterPageFile="~/Forum.master" AutoEventWireup="true" CodeBehind="ForumTopicPage.aspx.cs" Inherits="Forums.ForumTopicPage" %>
<%@ Register src="UserControls/SearchFunction.ascx" tagname="SearchFunction" tagprefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="searchContentHolder" runat="server">
    <uc1:SearchFunction ID="SearchFunction1" runat="server" />
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="mainContentHolder" runat="server">
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataKeyNames="topic_id" DataSourceID="ForumTopicPageGrid"
        AllowPaging="True" >
        <Columns>
                    <asp:TemplateField HeaderText="Thread" SortExpression="thread_subject">
                <ItemTemplate>
                    <asp:HyperLink ID="HyperLink1" runat="server" CssClass="threadLink" 
                        NavigateUrl='<%# Eval("topic_id", "ThreadPage.aspx?topicId={0}") %>' 
                        Text='<%# Eval("thread_subject") %>'></asp:HyperLink>
                    <br />
                    <asp:HyperLink ID="HyperLink2" runat="server" CssClass="subThread" 
                        NavigateUrl='<%# Eval("topic_id", "ThreadPage.aspx?topicId={0}") %>' 
                        Text='<%# Eval("thread_body") %>'>                        
                        </asp:HyperLink>
                </ItemTemplate>
                        <HeaderStyle CssClass="threadHeader" />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Started By">
                <ItemTemplate>
                    <%#Eval("Started by") %>
                    <br />
                    <img src="UserAvatar.aspx?user_id=<%#Eval("user_accnt") %>" alt="N/A" />
                </ItemTemplate>
            </asp:TemplateField>

            <asp:BoundField DataField="date_posted" HeaderText="Date Posted" 
                SortExpression="date_posted" DataFormatString="{0:D}" >
                    <HeaderStyle CssClass="threadHeader" />
                    </asp:BoundField>
            <asp:TemplateField HeaderText="Posted By">
                <ItemTemplate>
                    <%#Eval("Last Posting by")%>                    
                    
                </ItemTemplate>
            </asp:TemplateField>
            <asp:HyperLinkField DataNavigateUrlFields="topic_id"    
                DataNavigateUrlFormatString="ReportPage.aspx?topicId={0}" Text="Report This"  >
                <ControlStyle CssClass="hyperlink" />
                <HeaderStyle CssClass="threadHeader" />
                    </asp:HyperLinkField>
        </Columns>
    </asp:GridView>
   
        <asp:Button ID="btnCreate" runat="server" Text="Start  A New Subject" 
            onclick="btnCreate_Click" CssClass="submitButton" />
    <asp:SqlDataSource ID="ForumTopicPageGrid" runat="server" 
        ConnectionString="<%$ ConnectionStrings:CentForumsDB %>" SelectCommand="SELECT 
	topic.topic_id,
	topic.refers_to,
	topic.thread_subject,
	topic.thread_body,
	registration.member_name AS &quot;Started by&quot;,
	topic.date_posted,
	registration.user_accnt,
	(SELECT TOP 1
	registration.member_name AS &quot;Last Posting by&quot;
FROM
	topic AS reply INNER JOIN registration ON reply.user_accnt = registration.user_accnt
WHERE reply.refers_to = topic.topic_id AND topic.deleted != 1
ORDER BY reply.date_posted DESC) AS &quot;Last Posting By&quot;
FROM
	topic INNER JOIN registration ON topic.user_accnt = registration.user_accnt
WHERE topic.refers_to = @topicId
">
        <SelectParameters>
            <asp:QueryStringParameter Name="topicId" QueryStringField="topicId" />
        </SelectParameters>
    </asp:SqlDataSource>
</asp:Content>
